const reqInterface = require('../../../../api/models')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    houseList: [],
    info: {
      id: 0,
      house_id: 0,
      name: ''
    }
  },
  onLoad(opt) {
    let self = this;
    if (opt.id) {
      self.setData({
        'info.id': opt.id,
        'info.name': opt.name,
        'info.house_id': opt.house_id
      })
      self.getHouse()
    }
  },

  onShow() {
    let self = this;
    self.getHouse()
  },

  submit() {
    let self = this;
    reqInterface.PostRoom(self.data.info).then(res => {
      wx.showToast({
        title: '提交成功',
        icon: 'none'
      })
      wx.navigateBack()
    })
  },

  getHouse() {
    let self = this;
    reqInterface.GetHouses({
      page: 1,
      limit: 100,
      name: '',
      id: 0
    }).then(res => {
      self.setData({
        houseList: res
      })
    })
  },

  houseIdValue(e) {
    let self = this;
    self.setData({
      'info.house_id': e.detail.val
    })
  },

  nameValue(e) {
    let self = this;
    self.setData({
      'info.name': e.detail.val
    })
  },
})